package com.stone.serverless.auth;

import cn.dev33.satoken.SaManager;
import cn.dev33.satoken.config.SaTokenConfig;
import cn.dev33.satoken.context.SaTokenContext;
import com.stone.serverless.auth.context.StoneSaTokenContext;
import com.stone.serverless.auth.interceptor.SaRouteInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/** https://sa-token.dev33.cn/doc/index.html#/
 * @Description: TODO
 * @Author: MECHREVO
 * @Date: 2022/1/27 8:52
 * @Version: 1.0.0
 */
@Configuration
public class SatokenConfig {

    /**
     * 获取配置Bean
     *
     * @return 配置对象
     */
    @Bean
    public SaTokenConfig getSaTokenConfig() {
        SaTokenConfig saTokenConfig = new SaTokenConfig();
        SaManager.setConfig(saTokenConfig);
        return saTokenConfig;
    }

    @Bean
    public SaTokenContext saTokenContext() {
        StoneSaTokenContext stoneSaTokenContext = new StoneSaTokenContext();
        SaManager.setSaTokenContext(stoneSaTokenContext);
        return stoneSaTokenContext;
    }


    @Bean
    public SaRouteInterceptor saRouteInterceptor() {
        SaRouteInterceptor saRouteInterceptor = new SaRouteInterceptor();
        SatokenComponentProvider.INSTANCE.add(saRouteInterceptor);
        return saRouteInterceptor;
    }
}
